function Cannon(option) {
  this.x = option.x || 0;
  this.y = option.y || 0;
  this.w = option.w || 0;
  this.h = option.w || 0;
  this.rotate = 0;
  this.speed = option.speed || 0;
  this.img = new Image();
  this.nowSpeed = 0;
  this.rotate = option.rotate || 0;
};
Cannon.prototype = {
  draw: function(num) {
    // var e = window.event;
    this.img.src = "img/cannon" + num + ".png";
    var a = num;
    if (a == 0) {
      a = 7;
    }
    this.h = a * 2.3 + 60;
    ctx.save();
    ctx.translate(this.x, this.y);
    ctx.rotate(this.rotate);
    //获取鼠标的位置
    ctx.drawImage(this.img, 0, 0, this.w, this.h, -this.w / 2 - 6, -this.h / 2 - 5, this.w, this.h);
    ctx.restore();
  }
}

function getAngle(px, py, mx, my) { //获得人物中心和鼠标坐标连线，与y轴正半轴之间的夹角
  var x = Math.abs(px - mx);
  var y = Math.abs(py - my);
  var z = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  var cos = y / z;
  var radina = Math.acos(cos); //用反三角函数求弧度
  var angle = Math.floor(180 / (Math.PI / radina)); //将弧度转换成角度
  if (mx >= px && my <= py) {
    angle = angle;
  }
  // 第二象限
  else if (mx <= px && my <= py) {
    angle = 360 - angle;
  }
  // 第三象限
  else if (mx <= px && my >= py) {
    angle = 180 + angle;
  }
  // 第四象限
  else if (mx >= px && my >= py) {
    angle = 180 - angle;
  }
  // console.log(angle)
  var an = angle * Math.PI / 180;
  return an;
  // console.log(an);
}
var CannonIndexChange = [{
  w: 74,

}]
var Cannon = new Cannon({
  x: canvas.width / 2 + 10,
  y: 768 - 40,
  w: 60,
  h: 70,
  rotate: 0,
});
